package org.lewis;

import org.lewis.service.NumOperate;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * java spi使用示例
 */
public class SpiConsumer {
    public static void main(String[] args) {
        ServiceLoader<NumOperate> loader = ServiceLoader.load(NumOperate.class);
        Iterator<NumOperate> iterator = loader.iterator();
        if (iterator.hasNext()) {
            NumOperate numOperate = iterator.next();
            System.out.println(numOperate.exec(1, 2));
        } else {
            throw new RuntimeException("classpath 中未找到服务org.lewis.service.NumOperate实现类");
        }
    }
}
